local skel = fk.CreateSkill {
  name = "efengqi__qizhi",
}

Fk:loadTranslationTable{
  ["efengqi__qizhi"] = "奇制",
  [":efengqi__qizhi"] = "结束阶段，你可以弃置一名本回合未成为过你使用牌目标的角色至多X张牌（X为你本回合使用牌数）。",
  ["#efengqi__qizhi-choose"] = "奇制：你可以弃置一名本回合未成为过你使用牌目标的角色至多 %arg 张牌",

  ["$efengqi__qizhi1"] = "声东击西，敌寇一网成擒。",
  ["$efengqi__qizhi2"] = "吾意不在此地，已遣别部出发。",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local num = 0
    local ban_tos = {}
    player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data
      if use.from == player then
        num = num + 1
        if use.tos then
          for _, to in ipairs(use.tos) do
            table.insertIfNeed(ban_tos, to)
          end
        end
      end
    end, Player.HistoryTurn)
    if num == 0 then return false end
    local targets = table.filter(room.alive_players, function (p)
      return not p:isNude() and not table.contains(ban_tos, p)
    end)
    if #targets == 0 then return false end
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#efengqi__qizhi-choose:::" .. num,
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos, num = num })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    local num = event:getCostData(self).num
    local room = player.room
    local cards = room:askToChooseCards(player, {target = to, skill_name = skel.name, flag = "he", min = 1, max = num})
    room:throwCard(cards, skel.name, to, player)
  end,
})

return skel
